<template>
  <nav>
    <span class="city" @click="goToCity">{{ cityName }}</span>
    <ul>
      <li
        v-for="item in list"
        :key="item.title"
        :class="{ active: item.title === activeTitle }"
        @click="tab(item)"
      >
        {{ item.title }}
      </li>
    </ul>
    <span class="iconfont icon-sousuo"></span>
  </nav>
</template>

<script>
import { mapState } from "vuex";

export default {
  data() {
    return {
      list: [
        {
          title: "热映",
          url: "hot",
        },
        {
          title: "影院",
          url: "cinema",
        },
        {
          title: "待映",
          url: "wait",
        },
        {
          title: "经典电影",
          url: "classic",
        },
      ],
      activeTitle: "热映",
    };
  },
  // computed: {
  //   cityName() {
  //     return this.$store.state.cityName;
  //   },
  // },
  // computed: mapState(["cityName"]),
  computed: mapState({
    cityName: (state) => state.city.cityName,
  }),
  methods: {
    goToCity() {
      // 编程式导航
      this.$router.push("/city");
    },
    tab(item) {
      this.activeTitle = item.title;
      this.$router.push("/home/movies/" + item.url);
    },
  },
};
</script>

<style lang="less" scoped>
@import "../../../../assets/css/var.less";
nav {
  width: 100%;
  height: 44px;
  background: @white-color;
  border-bottom: 1px solid @border-color;
  display: flex;
  font-size: @s-font;

  .city {
    width: 62px;
    .center();
  }

  .iconfont {
    width: 45px;
    .center();
    color: @theme-color;
  }

  ul {
    flex: 1;
    display: flex;
    padding: 0 20px;

    li {
      flex: 2;
      .center();
      font-weight: 700;
      color: #666;
    }

    li:last-child {
      flex: 3;
    }

    .active {
      font-size: @m-font;
      color: #333;
      position: relative;

      &::after {
        content: "";
        position: absolute;
        width: 20px;
        height: 3px;
        background: @theme-color;
        left: 50%;
        transform: translateX(-50%);
        bottom: 5px;
        border-radius: 1.5px;
      }
    }
  }
}
</style>
